package com.yiip.mr.wordcount;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

//wordcount 官方reduce实例，reducer类
public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {

	int sum = 0;
	
	IntWritable iw = new IntWritable();

	@Override
	protected void reduce(Text key, Iterable<IntWritable> values, Context context)
			throws IOException, InterruptedException {
		//1、求和
		for (IntWritable intWritable : values) {
			sum += intWritable.get();
		}
		//2、输出
		iw.set(sum);
		context.write(key, iw);
		
	}
}
